home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.orig.lzh / input / newsrun < prev    next >
Text File  |  1989-06-27  |  3KB  |  139 lines

  1. #! /bin/sh
  2. # Process spooled news.
  3.  
  4. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  5. . ${NEWSCONFIG-/usr/lib/news/bin/config}
  6.  
  7. PATH=$NEWSCTL/bin:$NEWSBIN/input:$NEWSBIN/relay:$NEWSBIN:$NEWSPATH ; export PAT
  8.  
  9. umask $NEWSUMASK
  10.  
  11. here="$NEWSARTS/in.coming"
  12. cd $here
  13.  
  14. # First, is it worth trying at all?
  15. if test -r stop
  16. then
  17.     exit 0
  18. fi
  19.  
  20. # Lock against others running.
  21. lock="$NEWSCTL/LOCKinput"
  22. ltemp="$NEWSCTL/L.$$"
  23. echo $$ >$ltemp
  24. trap "rm -f $ltemp ; exit 0" 0 1 2 15
  25. if newslock $ltemp $lock
  26. then
  27.     trap "rm -f $ltemp $lock ; exit 0" 0 1 2 15
  28. else
  29.     exit 0
  30. fi
  31.  
  32. # Get rid of any old temporaries.
  33. rm -f nruntmp.*
  34. for f in `ls | egrep '^nspool'`
  35. do
  36.     find $f -mtime +1 -exec rm -f '{}' ';'
  37. done
  38.  
  39. # Sort out where we are.
  40. me="`hostname`"
  41. if test -r $NEWSCTL/server
  42. then
  43.     server=`cat $NEWSCTL/server`
  44. else
  45.     server="$me"        # no server file --> we're it
  46. fi
  47.  
  48. # Master loop.
  49. while true
  50. do
  51.     # Find some work.
  52.     them=`ls | egrep '^[0-9]+$' | sort | sed 50q`
  53.     if test "$them" = ""
  54.     then
  55.         break
  56.     fi
  57.  
  58.     # Do it.
  59.     for f in $them
  60.     do
  61.         # Check for request to stop.
  62.         if test -r stop
  63.         then
  64.             exit 0
  65.         fi
  66.  
  67.         # Check space.  It is *probably* better to stop processing
  68.         # when things get too full.  (This test is actually a bit
  69.         # inaccurate since the batch may be compressed, but it's
  70.         # good enough to catch major space problems.)
  71.         batchsize=`sizeof $f`
  72.         if test " $batchsize" -eq 0        # empty batch
  73.         then
  74.             rm -f $f
  75.             continue        # ugh
  76.         fi
  77.         if test " `spacefor $batchsize articles`" -le 0
  78.         then
  79.             exit 0
  80.         fi
  81.  
  82.         # Decompress if necessary.
  83.         text=nruntmp.$$
  84.         if compress -d <$f >$text 2>/dev/null
  85.         then
  86.             rmlist="$f $text"
  87.         elif c7decode <$f 2>/dev/null | compress -d >$text 2>/dev/null
  88.         then
  89.             rmlist="$f $text"
  90.         else
  91.             rm -f $text
  92.             text=$f
  93.             rmlist="$f"
  94.         fi
  95.  
  96.         # Do it.  -r redirects stdout and stderr into logs.  -n makes
  97.         # history entries for refused articles; this is right for
  98.         # NNTP-feed sites and doesn't hurt uucp-feed sites unless
  99.         # they refuse a good fraction of what they get.
  100.         if test " $server" = " $me"    # if local
  101.         then
  102.             relaynews -r -n <$text
  103.         else
  104.             # N.B.: rsh always returns exit status 0!
  105.             rsh $server "PATH=$PATH relaynews -r -n" <$text
  106.         fi
  107.         st=$?
  108.         if test $st -ne 0
  109.         then
  110.             # trouble
  111.             if test ! -d bad
  112.             then
  113.                 mkdir bad
  114.             fi
  115.             bad=bad/$f
  116.  
  117.             if test -s bad/limit
  118.             then
  119.                 limit=`sed 1q bad/limit`
  120.             else
  121.                 limit=50
  122.             fi
  123.             nfiles=`ls bad | wc | awk '{print $1}'`
  124.             if test " $nfiles" -lt " $limit"
  125.             then
  126.                 mv $f $bad    # Not $text, save the ORIGINAL!
  127.             fi
  128.             echo "$server $consumer \`$bad' failed, status $st" |
  129.                             mail "$NEWSMASTER"
  130.         fi
  131.  
  132.         rm -f $rmlist
  133.     done
  134. done
  135.  
  136. find bad -mtime +7 -exec rm -f '{}' ';'
  137.  
  138. exit 0
  139.